package ca.uvic.group2.api;

import ca.uvic.group2.api.exceptions.*;
import java.rmi.Remote;
import java.rmi.RemoteException;

public interface DBServer extends Remote {

    public static String RMI_NAME = "G2DBServer";

        /**
     * Resets the db state by dropping and re-adding the system table structure
     */
        void initDatabase() throws CommException, RemoteException;

    /**
     * Gets the key associated with the given user name
     */
    int login(String username) throws LoginException, CommException, RemoteException;

    /**
     * Returns userInfo for the given user id.
     */
    UserInfo getUserInfo(int userId) throws CommException, RemoteException;

    /**
     * Issues to buy command for the given userId.
     *
     * @param order The stock quote and number of shares to buy;
     * @return A receipt that verifies the transaction
     */
    Receipt buy(int transId, int userId, PurchaseOrder order) throws CommException, RemoteException;

    /**
     * Add money to the user's account.
     *
     * @return A receipt that verifies the transaction.
     */
    Receipt addFunds(int transId, int userId, float amount) throws CommException, RemoteException;

    /**
     * Adds a new trigger to the database, and moves funds from the user's balance to
     * reserve balance.
     *
     * @return new trigger id
     */
    int addBuyTrigger(int userId, Trigger trigger) throws CommException, RemoteException;

    /**
     * Removes a trigger from the database, and moves funds from the user's reserve balance
     * to primary balance.
     */
    void cancelBuyTrigger(int userId, int triggerId) throws CommException, RemoteException;

    /**
     * Add a new sell trigger to the database, and moves the amount of user's stock into reserve.
     *
     * @return new trigger id
     */
    int addSellTrigger(int userId, Trigger trigger) throws CommException, RemoteException;

    /**
     * Removes a sell trigger from the database, and moves the amount of user's stock out of reserve.
     */
    void cancelSellTrigger(int userId, int triggerId) throws CommException, RemoteException;

    /**
     * Issues a sell command for the given userId
     */
    Receipt sell(int transId, int userId, PurchaseOrder order) throws CommException, RemoteException;


    // Is this needed?
    //int createUser(String username, String password) throws CommException, RemoteException;

}
